package eshin.blog.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import eshin.blog.beans.User;
import eshin.blog.dao.UserDAO;

@Repository("userDAO")
public class UserDAOImpl implements UserDAO {
	@Resource SessionFactory sessionFactory;
	public void add(User user) {
		sessionFactory.openSession().save(user);
	}

	public void delete(User user) {

	}

	public List queryAll() {
		return null;
	}

	public User queryByID(String username) {
		List list =  (List) sessionFactory.openSession().createQuery("From User  where username = ?" )
				                                       .setString(0,username)
				                                       .list();
		
		if(list.size() == 0) {
			return null;
		} else {
			return (User)list.get(0);
		}
	}

	public void update(User user) {

	}

}
